import request from '@/utils/request'

/**
 * 报名管理API接口
 */

// 分页查询报名列表
export function getEnrollmentPage(currentPage, pageSize, queryParams) {
  return request({
    url: `/api/enrollments/page/${currentPage}/${pageSize}`,
    method: 'get',
    params: queryParams
  })
}

// 根据ID查询报名详情
export function getEnrollmentById(enrollmentId) {
  return request({
    url: `/api/enrollments/${enrollmentId}`,
    method: 'get'
  })
}

// 学生报名项目
export function enrollProject(enrollmentData) {
  return request({
    url: '/api/enrollments',
    method: 'post',
    data: enrollmentData
  })
}

// 学生取消报名
export function cancelEnrollment(enrollmentId) {
  return request({
    url: `/api/enrollments/${enrollmentId}`,
    method: 'delete'
  })
}

// 审核报名
export function auditEnrollment(enrollmentId, status, rejectReason) {
  return request({
    url: `/api/enrollments/${enrollmentId}/audit`,
    method: 'put',
    params: { status, rejectReason }
  })
}

// 批量审核报名
export function batchAuditEnrollments(enrollmentIds, status, rejectReason) {
  return request({
    url: '/api/enrollments/batch-audit',
    method: 'put',
    data: enrollmentIds,
    params: { status, rejectReason }
  })
}

// 根据用户ID查询报名列表
export function getEnrollmentsByUserId(userId) {
  return request({
    url: `/api/enrollments/user/${userId}`,
    method: 'get'
  })
}

// 根据项目ID查询报名列表
export function getEnrollmentsByProjectId(projectId) {
  return request({
    url: `/api/enrollments/project/${projectId}`,
    method: 'get'
  })
}

// 获取报名状态列表
export function getEnrollmentStatuses() {
  return request({
    url: '/api/enrollments/statuses',
    method: 'get'
  })
}

// 根据状态查询报名列表
export function getEnrollmentsByStatus(status) {
  return request({
    url: `/api/enrollments/status/${status}`,
    method: 'get'
  })
}

// 检查用户是否已报名某项目
export function checkUserEnrollment(userId, projectId) {
  return request({
    url: '/api/enrollments/check-enrollment',
    method: 'get',
    params: { userId, projectId }
  })
}

// 统计某项目的报名人数
export function countEnrollmentsByProjectId(projectId) {
  return request({
    url: `/api/enrollments/count/project/${projectId}`,
    method: 'get'
  })
}

// 获取当前学生的报名列表
export function getMyEnrollments() {
  return request({
    url: '/api/enrollments/my-enrollments',
    method: 'get'
  })
}

// 检查项目是否可以报名
export function checkCanEnroll(projectId) {
  return request({
    url: `/api/enrollments/check-can-enroll/${projectId}`,
    method: 'get'
  })
}

// 获取我的报名统计信息
export function getMyEnrollmentStats() {
  return request({
    url: '/api/enrollments/my-stats',
    method: 'get'
  })
}

// 导出报名列表
export function exportEnrollments(queryParams) {
  return request({
    url: '/api/enrollments/export',
    method: 'get',
    params: queryParams,
    responseType: 'blob'
  })
}

// 获取报名统计数据
export function getEnrollmentStats() {
  return request({
    url: '/api/enrollments/stats',
    method: 'get'
  })
}

// 获取报名图表数据
export function getEnrollmentCharts(chartType) {
  return request({
    url: '/api/enrollments/charts',
    method: 'get',
    params: { chartType }
  })
}

// 检查报名冲突
export function checkEnrollmentConflicts() {
  return request({
    url: '/api/enrollments/check-conflicts',
    method: 'get'
  })
}

// 获取报名设置
export function getEnrollmentSettings() {
  return request({
    url: '/api/enrollments/settings',
    method: 'get'
  })
}

// 保存报名设置
export function saveEnrollmentSettings(settings) {
  return request({
    url: '/api/enrollments/settings',
    method: 'put',
    data: settings
  })
}